package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Bookskind;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.BookskindService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/bookskindController")
public class BookskindController {
	@Resource
	BookskindService bookskindService;
	@RequestMapping("/getAllBookskind")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Bookskind> getAllBookskind() throws Exception {
    	System.out.println("查询全部书籍种类");
		return bookskindService.getAllBookskinds();
    }

	@RequestMapping("/deleteBookskindByBkno/{bkno}")
	@ResponseBody
    public DTO<Bookskind> deleteBookskindByBkno(@PathVariable("bkno") String bkno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(bkno+"删除书籍种类");
    	return bookskindService.deleteBookskindByBkno(bkno);
    }

	@RequestMapping("/updateBookskindByBkno")
	@ResponseBody
	public DTO<Bookskind> updateBookskindByBkno(@RequestBody Bookskind bookskind) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改书籍种类");
		return bookskindService.updateBookskindByBkno(bookskind);
	}


	@RequestMapping("/addBookskind")
	@ResponseBody
	public DTO<Bookskind> addBookskind(@RequestBody Bookskind bookskind) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加书籍种类");
		System.out.println(bookskind);
 		return bookskindService.addBookskind(bookskind);
	}
	@RequestMapping("/getBookskindByPage")
	@ResponseBody
	public DTO<Bookskind> getBookskindByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return bookskindService.getBookskindByPage(pageInfo);
	}
	@RequestMapping("/selectBookskindWithbooks")
	@ResponseBody
	public DTO<Bookskind> selectBookskindWithbooks() throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询图书种类带上图书");
		return bookskindService.selectBookskindWithbooks();
	}
}